<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script>
    function delay(a) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(`延迟了${a}`)
        })
      })
    }
    // let p = delay().then((res) => {
    //   console.log('555')
    // })

    // async await的作用：可以让我们像写同步代码一样执行我们的异步代码
    // 语法糖
    async function xxx() {
      console.log('top')
      const result = await delay(1)
      console.log(result)
      const result1 = await delay(2)
      console.log(result1)
      const result2 = await delay(3)
      console.log(result2)
      console.log('bottom')
    }

    async function yyy() {
      console.log('top2')
      const result3 = await delay(4)
      console.log(result3)
      const result4 = await delay(5)
      console.log(result4)
      const result5 = await delay(6)
      console.log(result5)
      console.log('bottom2')
    }
      xxx()
      yyy()

    // async function chatRobot() {
    //   const res = await axios({
    //     url: 'http://ajax-api.itheima.net/api/robot?spoken=你饿不饿???',
    //   })
    //   console.log(res)
    //   const res1 = await axios({
    //     url: 'http://ajax-api.itheima.net/api/robot?spoken=你要不要吃点啥',
    //   })
    //   console.log(res1)
    //   const res2 = await axios({
    //     url: 'http://ajax-api.itheima.net/api/robot?spoken=我给你买包子',
    //   })
    //   console.log(res2)
    // }
    // chatRobot()
  </script>
</body>
</html>